﻿using UnityEditor;
using UnityEngine;

namespace CWM.Skinn
{
    public static partial class SkinnContextCommands
    {
        [CtxMenuItem("Renderer/Mesh/Normals/Clear", "Removes the vertex normals from a mesh(s).", 0)]
        public static void SkinnedMeshNormalsClear()
        {
            foreach (var item in SkinnContext.GetContextItems())
            {
                var context = item.GetComponent<Renderer>();
                if (SkinnEx.IsNullOrNotInAScene(context)) continue;
                if (!SkinnEx.HasMinimumRequirements(context)) continue;
                SkinnContext.UndoRecord(context, "Clear Normals");
                Mesh mesh = context.GetSharedMesh().Clone() as Mesh;
                mesh.normals = null;
                context.SetSharedMesh(mesh);
            }
            SkinnContext.Finished();
        }
    }
}